home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTValSet.z / RWTValSet
Encoding:
Text File  |  2002-10-03  |  20.6 KB  |  529 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTValSet<T,C> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/tvset.h>
  13.           RWTValSet<T,C> s;
  14.  
  15.  
  16.  
  17. SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!!
  18.  
  19.  
  20.  
  21.      RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt requires the Standard C++ Library.
  22.  
  23.  
  24. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  25.      This class maintains a collection of values, which are ordered according
  26.      to a comparison object of type CCCC.  CCCC must induce a total ordering on
  27.      elements of type TTTT via a public member
  28.           bbbboooooooollll ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt TTTT&&&& xxxx,,,, ccccoooonnnnsssstttt TTTT&&&& yyyy)))) ccccoooonnnnsssstttt which returns ttttrrrruuuueeee if
  29.      xxxx should precede yyyy within the collection.  The structure lllleeeessssssss<<<<TTTT>>>> from the
  30.      C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an example.  RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> will
  31.      not accept an item that compares equal to an item already in the
  32.      collection.  (RRRRWWWWTTTTVVVVaaaallllMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> may contain multiple items that compare
  33.      equal to each other.)  Equality is based on the comparison object and not
  34.      on the ======== operator.  Given a comparison object ccccoooommmmpppp, items aaaa and bbbb are
  35.      equal if
  36.           !!!!ccccoooommmmpppp((((aaaa,,,,bbbb)))) &&&&&&&& !!!!ccccoooommmmpppp((((bbbb,,,,aaaa)))).
  37.  
  38. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  39.      Isomorphic.
  40.  
  41. EEEExxxxaaaammmmpppplllleeeessss
  42.      In this example, a set of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs is exercised.
  43.  
  44.               //
  45.  
  46.  
  47.  
  48.               // tvsstr.cpp
  49.           //
  50.           #include <rw/tvset.h>
  51.           #include <rw/cstring.h>
  52.           #include <iostream.h>
  53.           #include <function.h>
  54.           main(){
  55.             RWTValSet<RWCString,less<RWCString> > set;
  56.             set.insert("one");
  57.             set.insert("two");
  58.             set.insert("three");
  59.             set.insert("one");     // Rejected: already in collection
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.             cout << set.entries() << endl;     // Prints "3"
  75.             return 0;
  76.  
  77. RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss
  78.      }
  79.  
  80.  
  81.      Class RRRRWWWWTTTTVVVVaaaallllMMMMuuuullllttttiiiiSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> offers the same interface to a collection that
  82.      accepts multiple items that compare equal to each other.
  83.      RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> maintains a collection of key-value pairs.  Class
  84.      sssseeeetttt<<<<TTTT,,,,CCCC,,,,aaaallllllllooooccccaaaattttoooorrrr>>>> is the C++-standard collection that serves as the
  85.      underlying implementation for RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>.
  86.  
  87. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss
  88.               typedef set<T,C,allocator>                     container_type;
  89.  
  90.  
  91.  
  92.               typedef container_type::iterator               iterator;
  93.           typedef container_type::const_iterator         const_iterator;
  94.           typedef container_type::size_type              size_type;
  95.           typedef T                                      value_type;
  96.           typedef const T&                               const_reference;
  97.  
  98. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  99.               RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const C& comp = C());
  100.  
  101.  
  102.      Constructs an empty set.
  103.  
  104.               RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const container_type& s);
  105.  
  106.  
  107.      Constructs a set by copying all elements of ssss.
  108.  
  109.               RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>(const RWTValSet<T,C>& rws);
  110.  
  111.  
  112.      Copy constructor.
  113.  
  114.               RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>>
  115.           (const T* first,const T* last,const C& comp = C());
  116.  
  117.  
  118.      Constructs a set by copying elements from the array of TTTTs pointed to by
  119.      ffffiiiirrrrsssstttt, up to, but not including, the element pointed to by llllaaaasssstttt.
  120.  
  121. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss
  122.               RWTValSet<T,C>&
  123.           ooooppppeeeerrrraaaattttoooorrrr====(const RWTValSet<T,C>& s);
  124.           RWTValSet<T,C>&
  125.           ooooppppeeeerrrraaaattttoooorrrr====(const container_type& s);
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      Destroys all elements of self and replaces them by copying all elements
  141.      of ssss....
  142.  
  143.               bool
  144.           ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTValSet<T,C>& s) const;
  145.           bool
  146.           ooooppppeeeerrrraaaattttoooorrrr<<<<(const container_type& s) const;
  147.  
  148.  
  149.      Returns ttttrrrruuuueeee if self compares lexicographically less than ssss, otherwise
  150.      returns ffffaaaallllsssseeee.  Assumes that type TTTT has well-defined less-than semantics
  151.      (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr<<<<((((ccccoooonnnnsssstttt TTTT&&&&)))) or equivalent).
  152.  
  153.               bool
  154.           ooooppppeeeerrrraaaattttoooorrrr========(const RWTValSet<T,C>& s) const;
  155.           bool
  156.           ooooppppeeeerrrraaaattttoooorrrr========(const set<T,C>& s) const;
  157.  
  158.  
  159.      Returns ttttrrrruuuueeee if self compares equal to ssss, otherwise returns ffffaaaallllsssseeee.  Two
  160.      collections are equal if both have the same number of entries, and
  161.      iterating through both collections produces, in turn, individual elements
  162.      that compare equal to each other.
  163.  
  164. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  165.               void
  166.           aaaappppppppllllyyyy(void (*fn)(const_reference,void*), void* d) const;
  167.  
  168.  
  169.      Applies the user-defined function pointed to by ffffnnnn to every item in the
  170.      collection.  This function must have prototype:
  171.  
  172.  
  173.  
  174.  
  175.  
  176.                  void yourfun(const_reference a, void* d);
  177.  
  178.  
  179.      Client data may be passed through parameter dddd.
  180.  
  181.               iterator
  182.           bbbbeeeeggggiiiinnnn();
  183.           const_iterator
  184.           bbbbeeeeggggiiiinnnn() const;
  185.  
  186.  
  187.      Returns an iterator positioned at the first element of self.
  188.  
  189.               void
  190.           cccclllleeeeaaaarrrr();
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      Clears the collection by removing all items from self.  Each item will
  207.      have its destructor called.
  208.  
  209.               bool
  210.           ccccoooonnnnttttaaaaiiiinnnnssss(const_reference a) const;
  211.  
  212.  
  213.      Returns ttttrrrruuuueeee if there exists an element tttt in self that compares equal to
  214.      aaaa, otherwise returns ffffaaaallllsssseeee.
  215.  
  216.               bool
  217.           ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const_reference,void*), void* d) const;
  218.  
  219.  
  220.      Returns ttttrrrruuuueeee if there exists an element tttt in self such that the
  221.      expression ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee.  ffffnnnn points to a
  222.      user-defined tester function which must have prototype:
  223.  
  224.  
  225.  
  226.  
  227.  
  228.                  bool yourTester(const_reference a, void* d);
  229.  
  230.  
  231.      Client data may be passed through parameter dddd.
  232.  
  233.               void
  234.           ddddiiiiffffffffeeeerrrreeeennnncccceeee(const RWTValSet<T,C>& s);
  235.           void
  236.           ddddiiiiffffffffeeeerrrreeeennnncccceeee(const container_type& s);
  237.  
  238.  
  239.      Sets self to the set-theoretic difference given by ((((sssseeeellllffff ---- ssss)))).
  240.  
  241.               iterator
  242.           eeeennnndddd();
  243.           const_iterator
  244.           eeeennnndddd() const;
  245.  
  246.  
  247.      Returns an iterator positioned "just past" the last element in self.
  248.  
  249.               size_type
  250.           eeeennnnttttrrrriiiieeeessss() const;
  251.  
  252.  
  253.      Returns the number of items in self.
  254.  
  255.               bool
  256.           ffffiiiinnnndddd(const_reference a, T& k) const;
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.      If there exists an element tttt in self that compares equal to aaaa, assigns tttt
  273.      to kkkk and returns ttttrrrruuuueeee.  Otherwise, returns ffffaaaallllsssseeee and leaves the value of
  274.      kkkk unchanged.
  275.  
  276.               bool
  277.           ffffiiiinnnndddd(bool (*fn)(const_reference,void*), void* d, T& k) const;
  278.  
  279.  
  280.      If there exists an element tttt in self such that the expression
  281.      ((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee, assigns tttt to kkkk and returns ttttrrrruuuueeee.  Otherwise,
  282.      returns ffffaaaallllsssseeee and leaves the value of kkkk unchanged.  ffffnnnn points to a user-
  283.      defined tester function which must have prototype:
  284.  
  285.  
  286.  
  287.  
  288.  
  289.                  bool yourTester(const_reference a, void* d);
  290.  
  291.  
  292.      Client data may be passed through parameter dddd.
  293.  
  294.               bool
  295.           iiiinnnnsssseeeerrrrtttt(const_reference a);
  296.  
  297.  
  298.      Adds the item aaaa to the collection.  Returns ttttrrrruuuueeee if the insertion is
  299.      successful, otherwise returns ffffaaaallllsssseeee.  The function will return ttttrrrruuuueeee
  300.      unless the collection already holds an element with the equivalent key.
  301.  
  302.               void
  303.           iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const RWTValSet<T,C>& s);
  304.           void
  305.           iiiinnnntttteeeerrrrsssseeeeccccttttiiiioooonnnn(const container_type& s);
  306.  
  307.  
  308.      Sets self to the intersection of self and ssss.
  309.  
  310.               bool
  311.           iiiissssEEEEmmmmppppttttyyyy() const;
  312.  
  313.  
  314.      Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise.
  315.  
  316.               bool
  317.           iiiissssEEEEqqqquuuuiiiivvvvaaaalllleeeennnntttt(const RWTValSet<T,C>& s) const;
  318.  
  319.  
  320.      Returns ttttrrrruuuueeee if there is set equivalence between self and ssss, and returns
  321.      ffffaaaallllsssseeee otherwise.
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               bool
  339.           iiiissssPPPPrrrrooooppppeeeerrrrSSSSuuuubbbbsssseeeettttOOOOffff(const RWTValSet<T,C>& s) const;
  340.  
  341.  
  342.      Returns ttttrrrruuuueeee if self is a proper subset of ssss, and returns ffffaaaallllsssseeee
  343.      otherwise.
  344.  
  345.               bool
  346.           iiiissssSSSSuuuubbbbsssseeeettttOOOOffff(const RWTValSet<T,C>& s) const;
  347.  
  348.  
  349.      Returns ttttrrrruuuueeee if self is a subset of ssss; ffffaaaallllsssseeee otherwise.
  350.  
  351.               size_type
  352.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const_reference a) const;
  353.  
  354.  
  355.      Returns the number of elements tttt in self that compare equal to aaaa.
  356.  
  357.               size_type
  358.           ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(bool (*fn)(const T&,void*),void* d) const;
  359.  
  360.  
  361.      Returns the number of elements tttt in self such that the
  362.      expression((((((((****ffffnnnn))))((((tttt,,,,dddd)))))))) is ttttrrrruuuueeee.  ffffnnnn points to a user-defined tester
  363.      function which must have prototype:
  364.  
  365.  
  366.  
  367.  
  368.  
  369.                  bool yourTester(const_reference a, void* d);
  370.  
  371.  
  372.      Client data may be passed through parameter dddd.
  373.  
  374.               bool
  375.           rrrreeeemmmmoooovvvveeee(const_reference a);
  376.  
  377.  
  378.      Removes the first element tttt in self that compares equal to aaaa and returns
  379.      ttttrrrruuuueeee.  Returns ffffaaaallllsssseeee if there is no such element.
  380.  
  381.               bool
  382.           rrrreeeemmmmoooovvvveeee(bool (*fn)(const_reference,void*), void* d);
  383.  
  384.  
  385.      Removes the first element tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))
  386.      is ttttrrrruuuueeee and returns ttttrrrruuuueeee.  Returns ffffaaaallllsssseeee if there is no such element.  ffffnnnn
  387.      points to a user-defined tester function which must have prototype:
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.                  bool yourTester(const_reference a, void* d);
  409.  
  410.  
  411.      Client data may be passed through parameter dddd.
  412.  
  413.               size_type
  414.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(const_reference a);
  415.  
  416.  
  417.      Removes all elements tttt in self that compare equal to aaaa.  Returns the
  418.      number of items removed.
  419.  
  420.               size_type
  421.           rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const_reference,void*), void* d);
  422.  
  423.  
  424.      Removes all elements tttt in self such that the expression ((((((((****ffffnnnn))))((((tttt,,,,dddd))))))))is
  425.      ttttrrrruuuueeee.  Returns the number of items removed.  ffffnnnn points to a user-defined
  426.      tester function which must have prototype:
  427.  
  428.  
  429.  
  430.  
  431.  
  432.                  bool yourTester(const_reference a, void* d);
  433.  
  434.  
  435.      Client data may be passed through parameter dddd.
  436.  
  437.               set<T,C,allocator>&
  438.           ssssttttdddd();
  439.           const set<T,C,allocator>&
  440.           ssssttttdddd() const;
  441.  
  442.  
  443.      Returns a reference to the underlying C++-standard collection that serves
  444.      as the implementation for self.  This reference may be used freely,
  445.      providing access to the C++-standard interface as well as
  446.      interoperability with other software components that make use of the
  447.      C++-standard collections.
  448.  
  449.               void
  450.           ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const RWTValSet<T,C>& s);
  451.           void
  452.           ssssyyyymmmmmmmmeeeettttrrrriiiiccccDDDDiiiiffffffffeeeerrrreeeennnncccceeee(const container_type& s);
  453.  
  454.  
  455.      Sets self to the symmetric difference of self and ssss.
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))                                                RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt((((3333CCCC++++++++))))
  467.  
  468.  
  469.  
  470.               void
  471.           UUUUnnnniiiioooonnnn(const RWTValSet<T,C>& s);
  472.           void
  473.           UUUUnnnniiiioooonnnn(const container_type& s);
  474.  
  475.  
  476.      Sets self to the union of self and ssss.  Note the use of the uppercase
  477.      "U"in UUUUnnnniiiioooonnnn to avoid conflict with the C++ reserved word.
  478.  
  479. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  480.               RWvostream&
  481.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTValSet<T,C>& coll);
  482.           RWFile&
  483.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValSet<T,C>& coll);
  484.  
  485.  
  486.      Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to
  487.      it if it has already been saved.
  488.  
  489.               RWvistream&
  490.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValSet<T,C>& coll);
  491.           RWFile&
  492.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValSet<T,C>& coll);
  493.  
  494.  
  495.      Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm.
  496.  
  497.               RWvistream&
  498.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValSet<T,C>*& p);
  499.           RWFile&
  500.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValSet<T,C>*& p);
  501.  
  502.  
  503.      Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a
  504.      new collection off the heap and sets pppp to point to it, or sets pppp to point
  505.      to a previously read instance.  If a collection is created off the heap,
  506.      then you are responsible for deleting it.
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.